<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>开灯关灯</title>
    <style>
        html, body {
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
    <button>关灯</button>
    <script>
        let btn = document.querySelector("button")
        btn.addEventListener("click", ()=>{
            let txt = btn.innerText;
            if(txt == "关灯"){
                btn.innerText = "开灯"
                document.body.style.backgroundColor = "black"
            }else{
                btn.innerText = "关灯"
                document.body.style.backgroundColor = "white"
            }
        })
    </script>
</body>
</html>